//
//  ZHYYPopBtn.m
//  ZHYYView
//
//  Created by MT-SW-005 on 2021/9/22.
//  Copyright © 2021 yuan zhang. All rights reserved.
//

#import "ZHYYPopBtn.h"

@implementation ZHYYPopBtn
{
    NSPopUpButton *popBtn;
    NSComboBox *comBox;
    NSSegmentedControl *seg;
    NSTextView *textv;
    NSImageView *imageView;
    NSProgressIndicator *progress;
}
- (void)drawRect:(NSRect)dirtyRect {
    [super drawRect:dirtyRect];
    
    // Drawing code here.
}
-(id)initWithFrame:(NSRect)frameRect{
    self =[super initWithFrame:frameRect];
    if (self) {
        [self createComBox];
        [self createa];
        [self createPopBtn];
//        [self creteImageView];
   
    }
    return self;
}


-(void)createPopBtn{
    popBtn =[[NSPopUpButton alloc]initWithFrame:CGRectMake(10,5, 150, 32)];
    popBtn.autoenablesItems=YES;
    [popBtn removeAllItems];
    [popBtn addItemsWithTitles:@[@"1",@"2",@"3"]];
    [popBtn setStringValue:@"pop Btn"];
    [popBtn setTarget:self];
    [popBtn setAction:@selector(popClick)];
    [self addSubview:popBtn];

}


-(void)popClick{
    NSLog(@"pop %@",popBtn.selectedItem.title);
}


-(void)creteImageView{
    imageView = [[NSImageView alloc]initWithFrame:CGRectMake(10, 10, 50, 50)];
    imageView.image =[NSImage imageNamed:@"greenLed.png"];
    [self addSubview:imageView];
}


-(void)createComBox{
    comBox=[[NSComboBox alloc] initWithFrame:CGRectMake(10, 40, 150, 32)];
    [comBox removeAllItems];
    [comBox addItemsWithObjectValues:@[@"1",@"2",@"3"]];
    [comBox setStringValue:@"comBox"];
    comBox.alignment =NSTextAlignmentCenter;
    comBox.font=[NSFont systemFontOfSize:14];
    [comBox setTarget:self];
    [comBox setAction:@selector(comBoxclick)];
    [self addSubview:comBox];
}

-(void)comBoxclick{
    NSLog(@"com %@",[comBox stringValue]);
}


-(void)createa{
    seg =[[NSSegmentedControl alloc] initWithFrame:CGRectMake(10, 80, 150, 32)];
    [seg setSegmentCount:3];
    [seg setLabel:@"1" forSegment:0];
    [seg setLabel:@"2" forSegment:1];
    [seg setLabel:@"3" forSegment:2];
    [seg setSelectedSegment:1];
    [seg setTarget:self];
    [seg setAction:@selector(segclick)];
    [self addSubview: seg];
}

-(void)segclick{
    NSLog(@"seg :%ld",seg.selectedSegment);
}




@end
